import AlumnuModel from "../models/AlumnuModel"
import {observable, action, toJS} from "mobx";

class AlumnusStore {
    api;
    appStore;
    @observable alumnuModel = new AlumnuModel();

    constructor(api, appStore) {
        this.api = api;
        this.appStore = appStore;
    }

    @action setModel(alumnuModel) {
        this.alumnuModel = alumnuModel;
    }

    @action getModel() {
        return this.alumnuModel;
    }

    //推荐优秀校友
    @action recommendateAlumnu(alumnuModel) {
        this.appStore.increaseRequest();
        return this.api.recommendateAlumnu(alumnuModel).then(
            action(data => {
                this.appStore.decreaseRequest();
                if (data === 0) {
                    alert("提交成功，感谢您的推荐");
                } else if (data === 1) {
                    alert("感谢您的推荐,该校友已被推荐");
                } else if (data === 2) {
                    alert("感谢您的推荐,该校友已确定为优秀校友");
                } else {
                    this.appStore.setError(data.error);
                }
                return Promise.reject();
            })
        );
    }
}

export default AlumnusStore;